package com.itheima.sc.web.pms;

import com.itheima.sc.api.pms.CateAttri_RelaApi;
import com.itheima.sc.pojo.pms.ProductAttribute;
import com.itheima.sc.pojo.pms.ProductCategoryAttributeRelation;
import com.itheima.sc.result.Result;
import com.itheima.sc.service.pms.ProductAttributeService;
import com.itheima.sc.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("productAttribute")
public class ProductAttributeController {
    @Autowired
    private ProductAttributeService attributeService;


    //根据商品分类的id获取商品属性及属性分类
    @GetMapping("attrInfo/{productCategoryId}")
    public Result attrInfo(@PathVariable Integer productCategoryId){
         List<Map<String,Integer>> list = attributeService.attrInfo(productCategoryId);
        return Result.success(list);
    }

    //添加商品属性信息
    @PostMapping("create")
    public Result create(@RequestBody ProductAttribute attribute){
        attributeService.create(attribute);
        return Result.success(null);
    }

    //批量删除商品属性
    @PostMapping("delete")
    public Result deleteByIds(@RequestParam List<Integer> ids){
        attributeService.deleteByIds(ids);
        return Result.success(null);
    }

    //分页根据分类查询属性列表或参数列表
    @GetMapping("list/{cid}")
    public Result listByType(@PathVariable Integer cid,
                             @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                             @RequestParam Integer type){
        PageResult pageResult = attributeService.listByType(cid,type,pageNum,pageSize);
        return Result.success(pageResult);
    }

    //修改商品属性信息
    @PostMapping("update/{id}")
    public Result updateById(@RequestBody ProductAttribute attribute){
        attributeService.updateById(attribute);
        return Result.success(null);
    }

    //查询单个商品属性
    @GetMapping("{id}")
    public Result getById(@PathVariable Integer id){
        ProductAttribute attribute = attributeService.getById(id);
        return Result.success(attribute);
    }















}
